//
//  MBSpaceMyParentChildShowPlayViewController.m
//  MiBaoTu
//
//  Created by admin on 16/9/20.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBStoryRecommendViewController.h"
#import "MBSpaceMyParentChildShowPlayViewController.h"
#import "MBSongDetailForIController.h"
#import "MBLoginController.h"
#import "AttentionView.h"
#import "MBSpaceMyParentChildShowPlayViewForIpadController.h"
@interface MBStoryRecommendViewController ()<AttentionViewDelegate> {
    UIScrollView                        *_scrollView;
    
    UIView                              *topView;
    UIImageView                         *bgImgView;
    UILabel                             *showLunboLb;
    
    UIView                              *bottomView;
    UIView                              *userView;
    UIImageView                         *_userImgView;
    UILabel                             *_nickNameLb;
    UILabel                             *_nickNameDetailLb;
    UIButton                            *guanzhuBt;
    UILabel                             *_timeLb;
    UILabel                             *_contentLb;
    
    NSMutableArray                      *_mutArr;
    
    AttentionView                       *_attentionView;
}

@end

@implementation MBStoryRecommendViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    if (guanzhuBt) {
        UserModel *model = [UserManager standerDefult].userModel;
        if (model && _dataDic) {
            if ([[_dataDic objectForKey:@"UserID"] intValue] == [model.UserID intValue]) {
                guanzhuBt.hidden = YES;
            } else {
                guanzhuBt.hidden = NO;
            }
        }
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    _mutArr = [[NSMutableArray alloc]init];
    // Do any additional setup after loading the view.
    
    [self onCreateUI];
    [self setBackItems];
    
    [self onLoadData];
}

#pragma mark - Actions
#pragma mark - UI
- (void)setBackItems
{
    [self setTitleView:@"小编推荐"];
    [self setBackItem];
    [self setRightPlayerItem];
}

- (void)onCreateUI
{
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.view.height)];
    _scrollView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_scrollView];
    
    //1.上部分
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 760*PERCEN)];
    topView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:topView];
    
    //背景图
    bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 500*PERCEN)];
    bgImgView.image = [UIImage imageNamed:@"zb_bg"];
    if (ISIPAD) {
     bgImgView.image = [UIImage imageNamed:@"banner_xbtj_1.0"];
    }
    [topView addSubview:bgImgView];
    
    showLunboLb = [[UILabel alloc]initWithFrame:CGRectMake((ISIPAD?460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), bgImgView.bottom, (ISIPAD?topView.width-920*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):topView.width-50*PERCEN), 20)];
    showLunboLb.backgroundColor = [UIColor clearColor];
    showLunboLb.textAlignment = NSTextAlignmentLeft;
    showLunboLb.textColor = UIColorFromHex(0x333333);
    showLunboLb.font = [UIFont systemFontOfSize:13.f];
    showLunboLb.numberOfLines = 0;
    [topView addSubview:showLunboLb];
  
    //感想
    NSString *lunbo = [_dataDic objectForKey:@"Signature"];
    if ([lunbo isKindOfClass:[NSNull class]]) {
        lunbo = @"";
    }
    NSMutableParagraphStyle *mtStyle = [[NSMutableParagraphStyle alloc]init];
    mtStyle.lineSpacing = 15*PERCEN;
    NSMutableAttributedString *mtAttribute = [[NSMutableAttributedString alloc]initWithString:lunbo];
    [mtAttribute addAttribute:NSFontAttributeName value:showLunboLb.font range:NSMakeRange(0, lunbo.length)];
    [mtAttribute addAttribute:NSParagraphStyleAttributeName value:mtStyle range:NSMakeRange(0, lunbo.length)];
    float lunboHeight = [mtAttribute boundingRectWithSize:CGSizeMake(showLunboLb.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height+10;
    showLunboLb.height = lunboHeight;
    showLunboLb.attributedText = mtAttribute;
    topView.height = 500*PERCEN + lunboHeight;
    
    //2.主播信息
    bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, topView.bottom+20*PERCEN, topView.width, 430*PERCEN)];
    bottomView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:bottomView];
    
    //主播头像等
    userView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, bottomView.width, 150*PERCEN)];
    userView.backgroundColor = UIColorFromHex(0x8ccaee);
    [bottomView addSubview:userView];
    //头像
    NSString *faceImg = [_dataDic objectForKey:@"FaceImg"];
    if ([faceImg isKindOfClass:[NSNull class]]) {
        faceImg = @"";
    }
    _userImgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD?500*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), (userView.height-110*PERCEN)/2., 110*PERCEN, 110*PERCEN)];
    _userImgView.backgroundColor = [UIColor clearColor];
    _userImgView.layer.cornerRadius = _userImgView.height / 2.;
    if (faceImg.length > 0) {
        [_userImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,faceImg]] placeholderImage:[UIImage imageNamed:@"xiaobian_bg"]];
    } else {
        _userImgView.image = [UIImage imageNamed:@"xiaobian_bg"];
    }
    _userImgView.layer.masksToBounds = YES;
    [userView addSubview:_userImgView];
    
    _nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(_userImgView.right+20*PERCEN, userView.height/2.-20-2*PERCEN, 200, 20)];
    _nickNameLb.backgroundColor = [UIColor clearColor];
    _nickNameLb.textAlignment = NSTextAlignmentLeft;
    _nickNameLb.textColor = UIColorFromHex(0xffffff);
    _nickNameLb.font = [UIFont systemFontOfSize:14.f];
    _nickNameLb.text = [NSString stringWithFormat:@"%@",[_dataDic objectForKey:@"NickName"]];
    [userView addSubview:_nickNameLb];
    
    
    guanzhuBt = [UIButton buttonWithType:UIButtonTypeCustom];
    guanzhuBt.frame = CGRectMake(userView.width-160*PERCEN-(ISIPAD?500*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), (userView.height-60*PERCEN)/2., 160*PERCEN, 60*PERCEN);
    guanzhuBt.backgroundColor = [UIColor clearColor];
    [guanzhuBt setImage:[UIImage imageNamed:@"jiaguanzhu"] forState:UIControlStateNormal];
    [guanzhuBt setImage:[UIImage imageNamed:@"yiguanzhu"] forState:UIControlStateSelected];
    [guanzhuBt addTarget:self action:@selector(onSelectBtForGuanZhu:) forControlEvents:UIControlEventTouchUpInside];
    [userView addSubview:guanzhuBt];
    UserModel *model = [UserManager standerDefult].userModel;
    if ([[_dataDic objectForKey:@"UserID"] intValue] == [model.UserID intValue]) {
        guanzhuBt.hidden = YES;
    } else {
        guanzhuBt.hidden = NO;
    }
    
    _nickNameDetailLb = [[UILabel alloc]initWithFrame:CGRectMake(_userImgView.right+20*PERCEN, userView.height/2.+2*PERCEN, guanzhuBt.left-_userImgView.right-20*PERCEN, 20)];
    _nickNameDetailLb.backgroundColor = [UIColor clearColor];
    _nickNameDetailLb.textAlignment = NSTextAlignmentLeft;
    _nickNameDetailLb.textColor = UIColorFromHex(0xffffff);
    _nickNameDetailLb.font = [UIFont systemFontOfSize:12.f];
    _nickNameDetailLb.text = [NSString stringWithFormat:@"%@",[_dataDic objectForKey:@"Describe"]];
    [userView addSubview:_nickNameDetailLb];
    
    _contentLb = [[UILabel alloc]initWithFrame:CGRectMake((ISIPAD?460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), userView.bottom+10*PERCEN, (ISIPAD?bottomView.width-2*460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):bottomView.width-2*25*PERCEN), 20)];
    _contentLb.backgroundColor = [UIColor clearColor];
    _contentLb.textAlignment = NSTextAlignmentLeft;
    _contentLb.textColor = UIColorFromHex(0x333333);
    _contentLb.font = [UIFont systemFontOfSize:12.f];
    _contentLb.numberOfLines = 0;
    [bottomView addSubview:_contentLb];
    
    NSString *str = [_dataDic objectForKey:@"Describe"];
    if ([str isKindOfClass:[NSNull class]]) {
        str = @"";
    }
    NSMutableParagraphStyle *mutStyle = [[NSMutableParagraphStyle alloc]init];
    mutStyle.lineSpacing = 12*PERCEN;
    
    NSMutableAttributedString *mutAttribute = [[NSMutableAttributedString alloc]initWithString:str];
    [mutAttribute addAttribute:NSFontAttributeName value:_contentLb.font range:NSMakeRange(0, str.length)];
    [mutAttribute addAttribute:NSParagraphStyleAttributeName value:mutStyle range:NSMakeRange(0, str.length)];
    float heiht = [mutAttribute boundingRectWithSize:CGSizeMake(_contentLb.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height+10;
    _contentLb.height = heiht;
    _contentLb.attributedText = mutAttribute;
    
    float allHeight = _contentLb.bottom;
    float itemJU = (ISIPAD?40:20)*PERCEN;
    float itemWidth = (ISIPAD?bottomView.width-2*460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):bottomView.width - itemJU)/2.;
    float itemHeight = itemWidth*268/340.;
    for (int i=0; i<2; i++) {
        UIImageView *tipImgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD?460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN)+(itemWidth+itemJU)*i, _contentLb.bottom+15*PERCEN, itemWidth, itemHeight)];
        tipImgView.backgroundColor = [UIColor clearColor];
        tipImgView.layer.cornerRadius = 5.;
        tipImgView.image = [UIImage imageNamed:@"zx_show_bg"];
        tipImgView.layer.masksToBounds = YES;
        tipImgView.tag = 2000+i;
        [bottomView addSubview:tipImgView];
        
        UIButton *tipBt = [UIButton buttonWithType:UIButtonTypeCustom];
        tipBt.frame = tipImgView.frame;
        tipBt.tag = 2500+i;
        tipBt.backgroundColor = [UIColor clearColor];
        [tipBt setImage:[UIImage imageNamed:@"bofang_xbtj"] forState:UIControlStateNormal];
        [tipBt setImage:[UIImage imageNamed:@"zanting_xbtj"] forState:UIControlStateSelected];
        [tipBt addTarget:self action:@selector(onSelectBtForPlayAudio:) forControlEvents:UIControlEventTouchUpInside];
        [bottomView addSubview:tipBt];
        
        allHeight = tipImgView.bottom+20*PERCEN;
    }
    bottomView.height = allHeight;
    
    _scrollView.contentSize = CGSizeMake(_scrollView.width, (_scrollView.height >= bottomView.bottom ? _scrollView.height : bottomView.bottom));
    
    _attentionView = [[AttentionView alloc]initWithTitle:@"是否要取消关注？" withCancelBt:@"取消关注" withSureBt:@"取消"];
    _attentionView.delegate = self;
    _attentionView.orientation = self.orientation;
}

- (void)onUpdateUIForView:(UIDeviceOrientation)orientation
{
    _scrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.view.height);
    
    topView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 760*PERCEN);
    bgImgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 500*PERCEN);
    
    NSMutableParagraphStyle *mtStyle = [[NSMutableParagraphStyle alloc]init];
    mtStyle.lineSpacing = 15*PERCEN;
    NSMutableAttributedString *mtAttribute = [[NSMutableAttributedString alloc]initWithString:showLunboLb.text];
    [mtAttribute addAttribute:NSFontAttributeName value:showLunboLb.font range:NSMakeRange(0, showLunboLb.text.length)];
    [mtAttribute addAttribute:NSParagraphStyleAttributeName value:mtStyle range:NSMakeRange(0, showLunboLb.text.length)];
    showLunboLb.frame = CGRectMake((ISIPAD?460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), bgImgView.bottom, (ISIPAD?topView.width-920*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):topView.width-50*PERCEN), 20);
    float lunboHeight = [mtAttribute boundingRectWithSize:CGSizeMake(showLunboLb.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height+10;
    showLunboLb.height = lunboHeight;
    topView.height = bgImgView.height + lunboHeight;
    
     //2.主播信息
    bottomView.frame = CGRectMake(0, topView.bottom+20*PERCEN, topView.width, 430*PERCEN);
    userView.frame = CGRectMake(0, 0, bottomView.width, 150*PERCEN);
    _userImgView.frame = CGRectMake((ISIPAD?500*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), (userView.height-110*PERCEN)/2., 110*PERCEN, 110*PERCEN);
    _nickNameLb.frame = CGRectMake(_userImgView.right+20*PERCEN, userView.height/2.-20-2*PERCEN, 200, 20);
    _nickNameDetailLb.frame = CGRectMake(_userImgView.right+20*PERCEN, userView.height/2.+2*PERCEN, 200, 20);
    guanzhuBt.frame = CGRectMake(userView.width-160*PERCEN-(ISIPAD?500*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), (userView.height-60*PERCEN)/2., 160*PERCEN, 60*PERCEN);
    
    _contentLb.frame = CGRectMake((ISIPAD?460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), userView.bottom+10*PERCEN, (ISIPAD?bottomView.width-2*460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):bottomView.width-2*25*PERCEN), 20);
    NSMutableParagraphStyle *mutStyle = [[NSMutableParagraphStyle alloc]init];
    mutStyle.lineSpacing = 12*PERCEN;
    
    NSMutableAttributedString *mutAttribute = [[NSMutableAttributedString alloc]initWithString:_contentLb.text];
    [mutAttribute addAttribute:NSFontAttributeName value:_contentLb.font range:NSMakeRange(0, _contentLb.text.length)];
    [mutAttribute addAttribute:NSParagraphStyleAttributeName value:mutStyle range:NSMakeRange(0, _contentLb.text.length)];
    float heiht = [mutAttribute boundingRectWithSize:CGSizeMake(_contentLb.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height+10;
    _contentLb.height = heiht;
    
    float allHeight = _contentLb.bottom;
    float itemJU = (ISIPAD?40:20)*PERCEN;
    float itemWidth = (ISIPAD?bottomView.width-2*460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):bottomView.width - itemJU)/2.;
    float itemHeight = itemWidth*268/340.;
    for (int i=0; i<2; i++) {
        UIImageView *tipImgView = (UIImageView *)[bottomView viewWithTag:2000+i];
         UIButton *tipBt = (UIButton *)[bottomView viewWithTag:2500+i];
        
        tipImgView.frame = CGRectMake((ISIPAD?460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN)+(itemWidth+itemJU)*i, _contentLb.bottom+15*PERCEN, itemWidth, itemHeight);
        tipBt.frame = tipImgView.frame;
        
        allHeight = tipImgView.bottom+20*PERCEN;
    }
    bottomView.height = allHeight;
    
    _scrollView.contentSize = CGSizeMake(_scrollView.width, (_scrollView.height >= bottomView.bottom ? _scrollView.height : bottomView.bottom));
}

#pragma mark - 数据加载
- (void)onLoadData
{
    //判断人气主播
    [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:STORY_ISHOTANTHOR_URL_PATH,[NSString stringWithFormat:@"%@",[_dataDic objectForKey:@"UserID"]]] view:nil success:^(id json) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
        if ([json[@"ret_code"] integerValue]==0) {
            NSArray *arr = json[@"data"];
            if ([arr isKindOfClass:[NSArray class]]) {
                NSDictionary *dic = [arr firstObject];
                _nickNameDetailLb.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"Describe"]];
            }
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
    
    //获取亲子秀
    NSString *idStr = [_dataDic objectForKey:@"UserID"];
    [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:STORY_GET_ANCHORAUDIO_URL_PATH,[NSString stringWithFormat:@"%@",idStr]] view:nil success:^(id json) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
        if ([json[@"ret_code"] integerValue]==0) {
            NSArray *arr = json[@"data"];
            if ([arr isKindOfClass:[NSArray class]]) {
                [_mutArr  removeAllObjects];
                [_mutArr addObjectsFromArray:arr];
                
                [self onLoadQinZiXiuForUI];
            }
        } else {
            [ErrorMessage showErrorMessage:json[@"message"] inView:self.view];
            [self onLoadQinZiXiuForUI];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
    
    //判断是否关注
    UserModel *model = [UserManager standerDefult].userModel;
    if (model) {
        //判断是否关注
        [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:STORY_ATTENTIONSTAUTS_URL_PATH,model.UserID,[_dataDic objectForKey:@"UserID"]] view:nil success:^(id json) {
            
            NSString *status = json[@"AttentionStatus"];
            if ([status intValue] == 0) {
                //没关注
                guanzhuBt.selected = NO;
            } else {
                guanzhuBt.selected = YES;
            }
            
        } failure:^(NSError *error) {
            
        }];
    }
    
    //小编背景
    NSString *bgRrl = [NSString stringWithFormat:STORY_BACKGROUND_URL_PATH,@5];
    [[HTTPManager standerDefault]AFGetRequest:bgRrl view:nil success:^(id json) {
        
        NSArray*arr=json[@"data"];
        if (arr.count>0) {
        
            NSDictionary *dic = [arr lastObject];
            NSString *urlPath = [dic objectForKey:@"PicPath"];
            UIImage *img = [UIImage imageNamed:@"zb_bg"];
            if (ISIPAD) {
                urlPath = [dic objectForKey:@"PicPath2"];
                img = [UIImage imageNamed:@"banner_xbtj_1.0"];
            }
            if (![urlPath isKindOfClass:[NSNull class]]) {
                [bgImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,urlPath]] placeholderImage:img];
            } else {
                bgImgView.image = img;
            }
        

        }
     
        NSString *status = json[@"AttentionStatus"];
        if ([status intValue] == 0) {
            //没关注
            guanzhuBt.selected = NO;
        } else {
            guanzhuBt.selected = YES;
        }
        
    } failure:^(NSError *error) {
        
    }];
}

- (void)onLoadQinZiXiuForUI
{
    UIImageView *tipImgView = (UIImageView *)[bottomView viewWithTag:2000];
    UIImageView *tip2ImgView = (UIImageView *)[bottomView viewWithTag:2001];
    UIButton *tipBt = (UIButton *)[bottomView viewWithTag:2500];
    UIButton *tip2Bt = (UIButton *)[bottomView viewWithTag:2501];
    
    if (_mutArr.count == 0) {
        tipImgView.hidden = YES;
        tip2ImgView.hidden = YES;
        tipBt.hidden = YES;
        tip2Bt.hidden = YES;
    }
    else if (_mutArr.count == 1) {
        tip2ImgView.hidden = YES;
        tip2Bt.hidden = YES;
        
        NSDictionary *dic = [_mutArr firstObject];
        NSString *coverPath = [dic objectForKey:@"CoverPath"];
        if ([coverPath isKindOfClass:[NSNull class]]) {
            coverPath = @"";
        }
        if (coverPath.length > 0) {
            [tipImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,coverPath]] placeholderImage:[UIImage imageNamed:@"zx_show_bg"]];
        } else {
            tipImgView.image = [UIImage imageNamed:@"zx_show_bg"];
        }
        tipBt.selected = NO;
    }
    else if (_mutArr.count >= 2) {
        NSDictionary *dic = [_mutArr firstObject];
        NSDictionary *dic1 = [_mutArr objectAtIndex:1];
        NSString *coverPath = [dic objectForKey:@"CoverPath"];
        NSString *coverPath1 = [dic1 objectForKey:@"CoverPath"];
        if ([coverPath isKindOfClass:[NSNull class]]) {
            coverPath = @"";
        }
        if (coverPath.length > 0) {
            [tipImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,coverPath]] placeholderImage:[UIImage imageNamed:@"zx_show_bg"]];
        } else {
            tipImgView.image = [UIImage imageNamed:@"zx_show_bg"];
        }
        tipBt.selected = NO;
        
        if ([coverPath1 isKindOfClass:[NSNull class]]) {
            coverPath1 = @"";
        }
        if (coverPath1.length > 0) {
            [tip2ImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,coverPath1]] placeholderImage:[UIImage imageNamed:@"zx_show_bg"]];
        } else {
            tip2ImgView.image = [UIImage imageNamed:@"zx_show_bg"];
        }
        tip2Bt.selected = NO;
    }
}

#pragma mark -方法
- (void)onBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

//关注
- (void)onSelectBtForGuanZhu:(UIButton *)bt
{
    if (!_dataDic) {
        return;
    }
    UserModel *model = [UserManager standerDefult].userModel;
    if (!model.UserID) {
        MBLoginController *registerLastVC = [[MBLoginController alloc] init];
        registerLastVC.formBaseViewCtrl = NSStringFromClass([self class]);
        [self.navigationController pushViewController:registerLastVC animated:YES];
        return;
    }
    
    if (bt.selected == NO) {
        //关注
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:FAMILYSHOW_MYATTENTION_ADD_URL_PATH,[_dataDic objectForKey:@"UserID"],model.UserID] view:nil success:^(id json) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            
            if ([json[@"ret_code"] integerValue]==0) {
                bt.selected = !bt.selected;
            }
            [ErrorMessage showErrorMessage:json[@"message"] inView:self.view];
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        }];
    } else {
        //取消关注
        if (_attentionView) {
            _attentionView.orientation = self.orientation;
            [_attentionView showInWindow];
        }
        
      
    }
    
    
}

#pragma mark - 提示框
- (void)onSelectSureItem:(AttentionView *)view
{
    
}

- (void)onSelectCancelItem:(AttentionView *)view
{
    //取消关注
    UserModel *model = [UserManager standerDefult].userModel;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:FAMILYSHOW_MYATTENTION_CANCEL_URL_PATH,[_dataDic objectForKey:@"UserID"],model.UserID] view:nil success:^(id json) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
        if ([json[@"ret_code"] integerValue]==0) {
            guanzhuBt.selected = !guanzhuBt.selected;
        }
        [ErrorMessage showErrorMessage:json[@"message"] inView:self.view];
        
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}

//播放音频
- (void)onSelectBtForPlayAudio:(UIButton *)bt
{

    NSString *idStr ;
    UserManager *manager = [UserManager standerDefult];
    //每个主播都有若干个亲子秀，所以需要个判断是哪个主播，这个主播的第几首歌
    if (manager.audioPlayerType != AudioPLayerType_ZhuBo) {
        [[UserManager standerDefult].musicArr removeAllObjects];
        [[UserManager standerDefult]setSelectMusicIndex:0];
        
        //初次进入
        idStr = @"";
        manager.audioPlayerType = AudioPLayerType_ZhuBo;
    } else {
        //2次进入
        idStr = @"";
        [manager setSelectMusicIndex:0];
        [manager.musicArr removeAllObjects];
        [manager.mainPlayer pause];
        
    }
    [manager setZhubo_SelectIndex:[NSString stringWithFormat:@"%@",@0]];
    manager.zhuboDic = (NSMutableDictionary *)_dataDic;
    
    
    if (ISIPAD) {
        MBSpaceMyParentChildShowPlayViewForIpadController*songDetailVC=[[MBSpaceMyParentChildShowPlayViewForIpadController alloc]init];
        songDetailVC.playTyle = MBSpaceMyParentChildShowPlayType_My1;
        songDetailVC.dataDic = _dataDic;
        songDetailVC.selectMusicID = idStr;
        [self.navigationController pushViewController:songDetailVC animated:YES];
        return;
    }

    
    MBSpaceMyParentChildShowPlayViewController *play = [[MBSpaceMyParentChildShowPlayViewController alloc]init];
    play.playTyle = MBSpaceMyParentChildShowPlayType_My1;
    play.dataDic = _dataDic;
    play.selectMusicID = idStr;
    [self.navigationController pushViewController:play animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
